package data;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

public class MemberDataBase {
        
        public static  MemberDataBase usersDataBase;
        
        Map<String,String> userToPassword;
        Map<String,Member> users;
        Vector<Member> loginUsers;
        int globalId;
        
        public MemberDataBase(){
                this.userToPassword = new HashMap<String, String>();
                this.users = new HashMap<String,Member>();
                this.loginUsers = new Vector<Member>();
                globalId =1;
                
        }
        
        public Member getMember(String userName)
        {
        	return users.get(userName);
        }
        
        public boolean addNewMember(String userName,String password){
                boolean ans = false;
                if (userToPassword.get(userName)==null){
                        userToPassword.put(userName, password);
                        users.put(userName,new Member(userName, globalId));
                        globalId++;
                        ans = true;
                }
                return ans;
        }
        
        public boolean authenticate(String userName,String password){
                boolean ans = false;
                String realPassword = userToPassword.get(userName);
                if (realPassword !=null){
                        ans = realPassword.equals(password);
                }
                return ans;
        }
        
        public static MemberDataBase getMembersDataBase()
        {
                if (usersDataBase == null)
                {
                        usersDataBase = new MemberDataBase();
                }
                return usersDataBase;
        }

		public void addLoginMember(Member u) {
			
			this.loginUsers.add(u);
			
		}
		
		public void removeLoginMember(Member u){
			this.loginUsers.remove(u);
		}
        

}
